//Written by Richard Lewis aka Trixmoto (c) 2007

function update(fld,val,typ) {
  //validation
  switch(typ) {
    case 0: //integer
      if(parseInt(val)!=val-0) {
        if(val=="") {
          val = 0;
          document.getElementsByName(fld)[0].value = 0;
        }
        else {
          alert('This field must contain an integer value!');
          setTimeout("myfocus('"+fld+"')",10);
          return false;
        }
      }
      break;
    case 1: //string
      val = val.replace(/\\/g,'\\\\');
      val = '"'+val+'"';
      break;
    case 2: //boolean
      break;      
  }
  
  //handle anchor exception
  if(fld.indexOf("anch")==0) {
    switch(fld.charAt(4)) {
      case "b":
        if(val) {
          val = MyProp.anch+8;
        }
        else {
          val = MyProp.anch-8;
        }
        break;
      case "r":
        if(val) {
          val = MyProp.anch+4;
        }
        else {
          val = MyProp.anch-4;
        }
        break;
      case "t":
        if(val) {
          val = MyProp.anch+2;
        }
        else {
          val = MyProp.anch-2;
        }
        break;
      case "l":
        if(val) {
          val = MyProp.anch+1;
        }
        else {
          val = MyProp.anch-1;
        }
        break;                
    }
    fld = "anch";
  }
  
  //update and repaint
  eval("MyProp."+fld+" = "+val);
  storeaction();
  document.getElementById('form').innerHTML = drawForm(MyForm);
  setpointer();
  return true;
}

function myfocus(fld) {
  var ele = document.getElementsByName(fld)[0];
  ele.value = 0;
  ele.focus();
  ele.select();
}

function propCommon(obj) {
  var temp = "<tr><td colspan=2>"+obj.onam+".Common.</td></tr>";
  temp = temp+"<tr><td class='propnam' width=50%>Align</td>";
  temp = temp+"<td width=50%><select name='alig' onchange=\"update('alig',this.value,0)\">";
  if (obj.alig==0) {
    temp = temp+"<option value='0' selected>None";
  }
  else {
    temp = temp+"<option value='0'>None";
  }
  if (obj.alig==1) {
    temp = temp+"<option value='1' selected>Top";
  }
  else {
    temp = temp+"<option value='1'>Top";
  }
  if (obj.alig==2) {
    temp = temp+"<option value='2' selected>Bottom";
  }
  else {
    temp = temp+"<option value='2'>Bottom";
  }
  if (obj.alig==3) {
    temp = temp+"<option value='3' selected>Left";
  }
  else {
    temp = temp+"<option value='3'>Left";    
  }
  if (obj.alig==4) {
    temp = temp+"<option value='4' selected>Right";
  }
  else {
    temp = temp+"<option value='4'>Right";
  }
  if (obj.alig==5) {
    temp = temp+"<option value='5' selected>Client";
  }
  else {
    temp = temp+"<option value='5'>Client";    
  }
  temp = temp+"</select></td></tr>"; 
  
  var a = obj.anch;
  temp = temp+"<tr><td class='propnam' width=50%>Anchors</td>";
  temp = temp+"<td width=50%>B<input type='checkbox' name='anchb' title='Bottom'";
  if (a>7) {
    a = a-8;
    temp = temp+" checked";
  }
  temp = temp+" onchange=\"update('anchb',this.checked,2)\"> R<input type='checkbox' name='anchr' title='Right'";
  if (a>3) {
    a = a-4;
    temp = temp+" checked";
  }
  temp = temp+" onchange=\"update('anchr',this.checked,2)\"> T<input type='checkbox' name='ancht' title='Top'";
  if (a>1) {
    a = a-2;
    temp = temp+" checked";
  }
  temp = temp+" onchange=\"update('ancht',this.checked,2)\"> L<input type='checkbox' name='anchl' title='Left'";
  if (a>0) {
    a = a-1;
    temp = temp+" checked";
  }  
  temp = temp+" onchange=\"update('anchl',this.checked,2)\"></td></tr>";  
  
/*
  temp = temp+"<tr><td class='propnam' width=50%>ClientHeight</td>";
  temp = temp+"<td width=50%><input type='text' name='clih' value='"+obj.clih;
  temp = temp+"' onchange=\"update('clih',this.value,0)\"></td></tr>";  
  
  temp = temp+"<tr><td class='propnam' width=50%>ClientWidth</td>";
  temp = temp+"<td width=50%><input type='text' name='cliw' value='"+obj.cliw;
  temp = temp+"' onchange=\"update('cliw',this.value,0)\"></td></tr>";  
*/
  
  temp = temp+"<tr><td class='propnam' width=50%>ControlName</td>";
  temp = temp+"<td width=50%><input type='text' name='name' value='"+obj.name;
  temp = temp+"' onchange=\"update('name',this.value,1)\"></td></tr>";  
  
  temp = temp+"<tr><td class='propnam' width=50%>Enabled</td>";
  temp = temp+"<td width=50%><input type='checkbox' name='enab'";
  if (obj.enab) {
    temp = temp+" checked";
  }
  temp = temp+" onchange=\"update('enab',this.checked,2)\"></td></tr>";  
  
  temp = temp+"<tr><td class='propnam' width=50%>Height</td>";
  temp = temp+"<td width=50%><input type='text' name='heig' value='"+obj.heig;
  temp = temp+"' onchange=\"update('heig',this.value,0)\"></td></tr>";  
  
  temp = temp+"<tr><td class='propnam' width=50%>Hint</td>";
  temp = temp+"<td width=50%><input type='text' name='hint' value='"+obj.hint;
  temp = temp+"' onchange=\"update('hint',this.value,1)\"></td></tr>"; 
  
  temp = temp+"<tr><td class='propnam' width=50%>Left</td>";
  temp = temp+"<td width=50%><input type='text' name='left' value='"+obj.left;
  temp = temp+"' onchange=\"update('left',this.value,0)\"></td></tr>";
  
  temp = temp+"<tr><td class='propnam' width=50%>MaxHeight</td>";
  temp = temp+"<td width=50%><input type='text' name='maxh' value='"+obj.maxh;
  temp = temp+"' onchange=\"update('maxh',this.value,0)\"></td></tr>";
  
  temp = temp+"<tr><td class='propnam' width=50%>MaxWidth</td>";
  temp = temp+"<td width=50%><input type='text' name='maxw' value='"+obj.maxw;
  temp = temp+"' onchange=\"update('maxw',this.value,0)\"></td></tr>"; 
  
  temp = temp+"<tr><td class='propnam' width=50%>MinHeight</td>";
  temp = temp+"<td width=50%><input type='text' name='minh' value='"+obj.minh;
  temp = temp+"' onchange=\"update('minh',this.value,0)\"></td></tr>"; 
  
  temp = temp+"<tr><td class='propnam' width=50%>MinWidth</td>";
  temp = temp+"<td width=50%><input type='text' name='minw' value='"+obj.minw;
  temp = temp+"' onchange=\"update('minw',this.value,0)\"></td></tr>"; 
  
  temp = temp+"<tr><td class='propnam' width=50%>Top</td>";
  temp = temp+"<td width=50%><input type='text' name='top' value='"+obj.top;
  temp = temp+"' onchange=\"update('top',this.value,0)\"></td></tr>"; 
  
  temp = temp+"<tr><td class='propnam' width=50%>Visible</td>";
  temp = temp+"<td width=50%><input type='checkbox' name='visi'";
  if (obj.visi) {
    temp = temp+" checked";
  }
  temp = temp+" onchange=\"update('visi',this.checked,2)\"></td></tr>";
  
  temp = temp+"<tr><td class='propnam' width=50%>Width</td>";
  temp = temp+"<td width=50%><input type='text' name='widt' value='"+obj.widt;
  temp = temp+"' onchange=\"update('widt',this.value,0)\"></td></tr>";
  return temp;
}

function propForm(form) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += form.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>BorderStyle</td>";
  html += "<td width=50%><select name='bord' onchange=\"update('bord',this.value,0)\">";
  if (form.bord==0) {
    html += "<option value='0' selected>None"; 
  }
  else {
    html += "<option value='0'>None";
  }
  if (form.bord==2) {
    html += "<option value='2' selected>Resizable";
  }
  else {
    html += "<option value='2'>Resizble";
  }
  if (form.bord==3) {
    html += "<option value='3' selected>Dialog";
  }
  else {
    html += "<option value='3'>Dialog";
  }
  if (form.bord==4) {
    html += "<option value='4' selected>ToolWindow";
  }
  else {
    html += "<option value='4'>ToolWindow";
  }
  if (form.bord==5) {
    html += "<option value='5' selected>SizeToolWin";
  }
  else {
    html += "<option value='5'>SizeToolWin";
  }
  html += "</select></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Caption</td>";
  html += "<td width=50%><input type='text' name='capt' value='"+form.capt;
  html += "' onchange=\"update('capt',this.value,1)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>FormPosition</td>";
  html += "<td width=50%><select name='posi' onchange=\"update('posi',this.value,0)\">";
  if (form.posi==0) {
    html += "<option value='0' selected>Designed"; 
  }
  else {
    html += "<option value='0'>Designed";
  }
  if (form.posi==1) {
    html += "<option value='1' selected>Default";
  }
  else {
    html += "<option value='1'>Default";
  }
  if (form.posi==4) {
    html += "<option value='4' selected>Center";
  }
  else {
    html += "<option value='4'>Center";
  }
  html += "</select></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>SavePositionName</td>";
  html += "<td width=50%><input type='text' name='save' value='"+form.save;
  html += "' onchange=\"update('save',this.value,1)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>StayOnTop</td>";
  html += "<td width=50%><input type='checkbox' name='stay'";
  if (form.stay) {
    html += " checked";
  }
  html += " onchange=\"update('stay',this.checked,2)\"></td></tr>";  
  
  html += propCommon(form);
  return html+"</table>";
}

function propActivex(act) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += act.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Component</td>";
  html += "<td width=50%><input type='text' name='comp' value='"+act.comp;
  html += "' onchange=\"update('comp',this.value,1)\"></td></tr>";  
  
  html += propCommon(act);
  return html+"</table>";
}

function propButton(but) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += but.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Cancel</td>";
  html += "<td width=50%><input type='checkbox' name='canc' title='Assigns ESC key to this button'";
  if (but.canc) {
    html += " checked";
  }
  html += " onchange=\"update('canc',this.checked,2)\"></td></tr>";  
  
  html += "<tr><td class='propnam' width=50%>Caption</td>";
  html += "<td width=50%><input type='text' name='capt' value='"+but.capt;
  html += "' onchange=\"update('capt',this.value,1)\"></td></tr>";  
  
  html += "<tr><td class='propnam' width=50%>Default</td>";
  html += "<td width=50%><input type='checkbox' name='defa' title='Assigns ENTER key to this button'";
  if (but.defa) {
    html += " checked";
  }
  html += " onchange=\"update('defa',this.checked,2)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>ModalResult</td>";
  html += "<td width=50%><input type='text' name='mres' title='Normally Default=1 and Cancel=2' value='"+but.mres;
  html += "' onchange=\"update('mres',this.value,0)\"></td></tr>";  
  
  html += "<tr><td class='propnam' width=50%>OnClickFunc</td>";
  html += "<td width=50%><input type='text' name='func' value='"+but.func;
  html += "' onchange=\"update('func',this.value,1)\"></td></tr>";
   
  html += "<tr><td class='propnam' width=50%>UseScript</td>";
  html += "<td width=50%><input type='text' name='uses' title='Only populate if not this script' value='"+but.uses;
  html += "' onchange=\"update('uses',this.value,1)\"></td></tr>";   
  
  html += propCommon(but);
  return html+"</table>";
}

function propDropDown(drp) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += drp.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Items</td>";
  html += "<td width=50%><input type='text' name='itms' title='Comma separated list of strings' value='"+drp.itms;
  html += "' onchange=\"update('itms',this.value,1)\"></td></tr>"; 
  
  html += "<tr><td class='propnam' width=50%>ItemIndex</td>";
  html += "<td width=50%><input type='text' name='itmi' value='"+drp.itmi;
  html += "' onchange=\"update('itmi',this.value,0)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>OnSelectFunc</td>";
  html += "<td width=50%><input type='text' name='func' value='"+drp.func;
  html += "' onchange=\"update('func',this.value,1)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Style</td>";
  html += "<td width=50%><select name='styl' onchange=\"update('styl',this.value,0)\">";
  if (drp.styl==0) {
    html += "<option value='0' selected>Editable"; 
  }
  else {
    html += "<option value='0'>Editable";
  }
  if (drp.styl==2) {
    html += "<option value='2' selected>Non-editable";
  }
  else {
    html += "<option value='2'>Non-editable";
  }
  html += "</select></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Text</td>";
  html += "<td width=50%><input type='text' name='text' value='"+drp.text;
  html += "' onchange=\"update('text',this.value,1)\"></td></tr>";  
   
  html += "<tr><td class='propnam' width=50%>UseScript</td>";
  html += "<td width=50%><input type='text' name='uses' title='Only populate if not this script' value='"+drp.uses;
  html += "' onchange=\"update('uses',this.value,1)\"></td></tr>";       
  
  html += propCommon(drp);
  return html+"</table>";
}

function propEdit(edt) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += edt.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Text</td>";
  html += "<td width=50%><input type='text' name='text' value='"+edt.text;
  html += "' onchange=\"update('text',this.value,1)\"></td></tr>";  
  
  html += propCommon(edt);
  return html+"</table>";
}

function propCheckBox(chk) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += chk.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Caption</td>";
  html += "<td width=50%><input type='text' name='capt' value='"+chk.capt;
  html += "' onchange=\"update('capt',this.value,1)\"></td></tr>";  

  html += "<tr><td class='propnam' width=50%>Checked</td>";
  html += "<td width=50%><input type='checkbox' name='chkd'";
  if (chk.chkd) {
    html += " checked";
  }
  html += " onchange=\"update('chkd',this.checked,2)\"></td></tr>";    
  
  html += propCommon(chk);
  return html+"</table>";
}

function propLabel(lbl) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += lbl.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Alignment</td>";
  html += "<td width=50%><select name='algn' onchange=\"update('algn',this.value,0)\">";
  if (lbl.algn==0) {
    html += "<option value='0' selected>Left"; 
  }
  else {
    html += "<option value='0'>Left";
  }
  if (lbl.algn==1) {
    html += "<option value='1' selected>Right";
  }
  else {
    html += "<option value='1'>Right";
  }  
  if (lbl.algn==2) {
    html += "<option value='2' selected>Center";
  }
  else {
    html += "<option value='2'>Center";
  }
  html += "</select></td></tr>";

  html += "<tr><td class='propnam' width=50%>Autosize</td>";
  html += "<td width=50%><input type='checkbox' name='auto'";
  if (lbl.auto) {
    html += " checked";
  }
  html += " onchange=\"update('auto',this.checked,2)\"></td></tr>";      
  
  html += "<tr><td class='propnam' width=50%>Caption</td>";
  html += "<td width=50%><input type='text' name='capt' value='"+lbl.capt;
  html += "' onchange=\"update('capt',this.value,1)\"></td></tr>";  

  html += "<tr><td class='propnam' width=50%>Multiline</td>";
  html += "<td width=50%><input type='checkbox' name='mult'";
  if (lbl.mult) {
    html += " checked";
  }
  html += " onchange=\"update('mult',this.checked,2)\"></td></tr>";    
  
  html += propCommon(lbl);
  return html+"</table>";
}

function propPanel(pan) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += pan.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>&nbsp;</td>";
  html += "<td width=50%>&nbsp;</td></tr>";  
  
  html += propCommon(pan);
  return html+"</table>";
}

function propRadioButton(rad) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += rad.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Caption</td>";
  html += "<td width=50%><input type='text' name='capt' value='"+rad.capt;
  html += "' onchange=\"update('capt',this.value,1)\"></td></tr>";  

  html += "<tr><td class='propnam' width=50%>Checked</td>";
  html += "<td width=50%><input type='checkbox' name='chkd'";
  if (rad.chkd) {
    html += " checked";
  }
  html += " onchange=\"update('chkd',this.checked,2)\"></td></tr>";    
  
  html += propCommon(rad);
  return html+"</table>";
}

function propSpinEdit(spn) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += spn.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>MaxValue</td>";
  html += "<td width=50%><input type='text' name='maxv' value='"+spn.maxv;
  html += "' onchange=\"update('maxv',this.value,0)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>MinValue</td>";
  html += "<td width=50%><input type='text' name='minv' value='"+spn.minv;
  html += "' onchange=\"update('minv',this.value,0)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Value</td>";
  html += "<td width=50%><input type='text' name='valu' value='"+spn.valu;
  html += "' onchange=\"update('valu',this.value,0)\"></td></tr>";  
  
  html += propCommon(spn);
  return html+"</table>";
}

function propTrackBar(bar) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += bar.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Horizontal</td>";
  html += "<td width=50%><input type='checkbox' name='hori'";
  if (bar.hori) {
    html += " checked";
  }
  html += " onchange=\"update('hori',this.checked,2)\"></td></tr>";  
  
  html += "<tr><td class='propnam' width=50%>MaxValue</td>";
  html += "<td width=50%><input type='text' name='maxv' value='"+bar.maxv;
  html += "' onchange=\"update('maxv',this.value,0)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>MinValue</td>";
  html += "<td width=50%><input type='text' name='minv' value='"+bar.minv;
  html += "' onchange=\"update('minv',this.value,0)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Value</td>";
  html += "<td width=50%><input type='text' name='valu' value='"+bar.valu;
  html += "' onchange=\"update('valu',this.value,0)\"></td></tr>";  
  
  html += propCommon(bar);
  return html+"</table>";
}

function propTranspPanel(tra) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += tra.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>&nbsp;</td>";
  html += "<td width=50%>&nbsp;</td></tr>";  
  
  html += propCommon(tra);
  return html+"</table>";
}

function propDockablePanel(doc) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += doc.onam+".</td></tr>";

  html += "<tr><td class='propnam' width=50%>Caption</td>";
  html += "<td width=50%><input type='text' name='capt' value='"+doc.capt;
  html += "' onchange=\"update('capt',this.value,1)\"></td></tr>";  
  
  html += "<tr><td class='propnam' width=50%>DockedTo</td>";
  html += "<td width=50%><select name='dock' onchange=\"update('dock',this.value,0)\">";
  if (doc.dock==0) {
    html += "<option value='0' selected>Undocked"; 
  }
  else {
    html += "<option value='0'>Undocked";
  }
  if (doc.dock==1) {
    html += "<option value='1' selected>Left";
  }
  else {
    html += "<option value='1'>Left";
  }  
  if (doc.dock==2) {
    html += "<option value='2' selected>Right";
  }
  else {
    html += "<option value='2'>Right";
  }
  if (doc.dock==3) {
    html += "<option value='3' selected>Top";
  }
  else {
    html += "<option value='3'>Top";
  }
  if (doc.dock==4) {
    html += "<option value='4' selected>Bottom";
  }
  else {
    html += "<option value='4'>Bottom";
  }
  html += "</select></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>Persistent</td>";
  html += "<td width=50%><input type='checkbox' name='pers'";
  if (doc.pers) {
    html += " checked";
  }
  html += " onchange=\"update('pers',this.checked,2)\"></td></tr>";  
  
  html += propCommon(doc);
  return html+"</table>";
}

function propOptionSheet(opt) {
  var html = "<table class='props' width=100%><tr><td colspan=2>";
  html += opt.onam+".</td></tr>";
  
  html += "<tr><td class='propnam' width=50%>SheetLabel</td>";
  html += "<td width=50%><input type='text' name='slab' value='"+opt.slab;
  html += "' onchange=\"update('slab',this.value,1)\"></td></tr>";
  
  html += "<tr><td class='propnam' width=50%>UseScript</td>";
  html += "<td width=50%><input type='text' name='uses' title='Only populate if not this script' value='"+opt.uses;
  html += "' onchange=\"update('uses',this.value,1)\"></td></tr>";  
  
  html += "<tr><td class='propnam' width=50%>InitProcedure</td>";
  html += "<td width=50%><input type='text' name='init' value='"+opt.init;
  html += "' onchange=\"update('init',this.value,1)\"></td></tr>";  
  
  html += "<tr><td class='propnam' width=50%>SaveProcedure</td>";
  html += "<td width=50%><input type='text' name='save' value='"+opt.save;
  html += "' onchange=\"update('save',this.value,1)\"></td></tr>";  
  
  html += "<tr><td class='propnam' width=50%>ParentID</td>";
  html += "<td width=50%><select name='pari' onchange=\"update('pari',this.value,0)\">";
  if (opt.pari==0) {
    html += "<option value='0' selected>(Last)"; 
  }
  else {
    html += "<option value='0'>(Last)";
  }
  if (opt.pari==1) {
    html += "<option value='1' selected>General";
  }
  else {
    html += "<option value='1'>General";
  }
  if (opt.pari==2) {
    html += "<option value='2' selected>Player";
  }
  else {
    html += "<option value='2'>Player";
  }  
  if (opt.pari==3) {
    html += "<option value='3' selected>Library";
  }
  else {
    html += "<option value='3'>Library";
  }
  if (opt.pari==4) {
    html += "<option value='4' selected>Portable";
  }
  else {
    html += "<option value='4'>Portable";
  }
  if (opt.pari==5) {
    html += "<option value='5' selected>Appearance";
  }
  else {
    html += "<option value='5'>Appearance";
  }
  html += "</select></td></tr>";
  
  return html+"</table>";
}
